package nicg.st.service;

import java.util.ArrayList;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import nicg.st.dao.RealTimeMapper;
import nicg.st.entity.HistInfos;
import nicg.st.entity.MyConfig;
import nicg.st.util.ErrorCode;
import nicg.st.util.ResponseUtil;

@Service
public class RealTimeService {
	
	@Resource
	RealTimeMapper realTimeMapper;
	@Resource
	MyConfig myConfig;

	public String getSchemeHist(String rwnm) {
		int realtimeLimit = Integer.parseInt(myConfig.getRealtimeLimit());
		List<HistInfos> histList = realTimeMapper.getSchemeHist(rwnm,realtimeLimit);
		
		return ResponseUtil.getResponseString(ErrorCode.SUCCESSFUL, "successful", histList);
	}

	
	public String getNodeHist(String rwnm, String NodeName) {
		int realtimeLimit = Integer.parseInt(myConfig.getRealtimeLimit());
		List<HistInfos> nodeList = new ArrayList<HistInfos>();
		List<HistInfos> histList = realTimeMapper.getSchemeHist(rwnm,realtimeLimit);
		
		for (HistInfos hist : histList) {
			HistInfos nodeInfos = new HistInfos();
			nodeInfos.setScore(realTimeMapper.getNodeHist(hist.getId(), NodeName));
			nodeInfos.setDate(hist.getDate());
			nodeList.add(nodeInfos);
		}
		
		return ResponseUtil.getResponseString(ErrorCode.SUCCESSFUL, "successful", nodeList);
	}

}
